package com.shopx.cm.controller;

import lombok.extern.slf4j.Slf4j;
import com.shopx.base.anno.ShopxParamAnno;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shopx.base.controller.BaseController;

import javax.annotation.Resource;

import com.shopx.cmm.DTO.PageDTO;
import com.shopx.base.dto.Result;
import com.shopx.base.utils.ResultUtil;
import com.shopx.base.exception.ShopxException;
import com.shopx.cm.bean.CmStore;
import com.shopx.cm.model.CmStoreModel;
import com.shopx.cm.service.ICmStoreService;

import com.shopx.base.anno.RepearSubmitChkAnno;
import com.shopx.core.common.CommonConstant;

/**
 * TODO
 *
 * @author lituo
 * @className: CmStoreController
 * @date 2025-01-08
 */
@RestController
@Slf4j
@RequestMapping(value = "/cmStore")
public class CmStoreController extends BaseController {

    @Resource
    private ICmStoreService cmStoreService;

    @PostMapping(value = "/queryPageList")
    @ShopxParamAnno
    public Result<PageDTO> queryPageList(@RequestBody CmStoreModel cmStore) throws ShopxException {
        PageDTO<CmStoreModel> pageDTO = cmStoreService.getListPage(cmStore);
        return ResultUtil.ok(pageDTO);
    }

    @PostMapping(value = "/insertOne")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<Integer> insertOne(@RequestBody CmStore cmStore) throws ShopxException {
        int result = cmStoreService.insertSelective(cmStore);
        return ResultUtil.ok(result);
    }

    @PostMapping(value = "/updateOne")
    @RepearSubmitChkAnno(lockTime = CommonConstant.REQ_TM)
    @ShopxParamAnno
    public Result<Integer> updateOne(@RequestBody CmStore cmStore) throws ShopxException {
        int result = cmStoreService.updateByPrimaryKeySelective(cmStore);
        return ResultUtil.ok(result);
    }

    @PostMapping(value = "/queryOneByPrimaryKey")
    public Result<CmStoreModel> queryOneByPrimaryKey(@RequestBody CmStore cmStore) throws ShopxException {
        CmStoreModel result = cmStoreService.selectByPrimaryKey(cmStore);
        return ResultUtil.ok(result);
    }

    /**
     * 同步店铺数据
     *
     * @return
     * @throws ShopxException
     */
    @PostMapping(value = "/syncErpData")
    public Result<?> syncErpData() throws ShopxException {
        cmStoreService.syncErpData();
        return ResultUtil.ok(true);
    }
}

